package cz.proks.easyhelpdesk.gae.core.ws;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cz.proks.easyhelpdesk.api.BaseApi;
import cz.proks.easyhelpdesk.api.exception.ApiException;
import cz.proks.easyhelpdesk.api.model.base.AnIdentifiableModel;
import cz.proks.easyhelpdesk.gae.core.manager.AManager;

public abstract class BaseApiImpl<Entity extends AnIdentifiableModel> implements BaseApi<Entity> {
	private final Logger log = LoggerFactory.getLogger(getClass());
	
	protected abstract AManager<Entity> getManager();
	
	@Override
	public Entity get(Long id) throws ApiException {
		log.debug("get():: Start with id '{}'", id);

		Entity entity = getManager().get(id);
		
		log.debug("get():: End with entity '{}'", entity);
		return entity;
	}

	@Override
	public Long create(Entity entity) throws ApiException {
		log.debug("create():: Start with entity '{}'", entity);
		
		Long id = getManager().create(entity);
		
		log.debug("create():: End with id '{}'", id);
		return id;
	}

	@Override
	public void update(Entity entity) throws ApiException {
		log.debug("update():: Start with entity '{}'", entity);
		
		getManager().update(entity);
		
		log.debug("update():: End");		
	}	

	@Override
	public void remove(Long id) throws ApiException {
		log.debug("delete():: Start with id '{}'", id);
				
		getManager().remove(id);
		
		log.debug("delete():: End");		
	}
}